/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.florent37.github.com.expansionpanel.slice;

import com.florent37.github.com.expansionpanel.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;

/**
 * lipeiquan
 *
 * @since 2021-05-06
 */
public class MainAbilitySlice extends AbilitySlice implements Component.ClickedListener {
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        findComponentById(ResourceTable.Id_sample).setClickedListener(this);
        findComponentById(ResourceTable.Id_sample_viewgroup).setClickedListener(this);
        findComponentById(ResourceTable.Id_programmatically).setClickedListener(this);
        findComponentById(ResourceTable.Id_recyclerView).setClickedListener(this);
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }

    @Override
    public void onClick(Component component) {
        int id = component.getId();
        switch (id) {
            case ResourceTable.Id_sample:
                jumpAbility("com.florent37.github.com.expansionpanel.ExpansionPanelSampleAbility");
                break;
            case ResourceTable.Id_sample_viewgroup:
                jumpAbility("com.florent37.github.com.expansionpanel.ExpansionPanelSampleAbilityViewGroup");
                break;
            case ResourceTable.Id_programmatically:
                jumpAbility("com.florent37.github.com.expansionpanel.ExpansionPanelSampleAbilityProgrammatically");
                break;
            case ResourceTable.Id_recyclerView:
                jumpAbility("com.florent37.github.com.expansionpanel.ExpansionPanelSampleAbilityRecycler");
                break;
            default:
                break;
        }
    }

    private void jumpAbility(String abilityName) {
        Intent secondIntent = new Intent();
        Operation operation = new Intent.OperationBuilder()
            .withDeviceId("")
            .withBundleName("com.florent37.github.com.expansionpanel")
            .withAbilityName(abilityName)
            .build();
        secondIntent.setOperation(operation);
        startAbility(secondIntent);
    }
}
